import { eventOverview } from "../../../../api/dashboard";
import { originEventOptions } from "../../../common/echartOption";

let eventStatus = false;
export default function useEventOverviewData(formState: any) {
  const eventOptions = JSON.parse(JSON.stringify(originEventOptions));
  return new Promise(resolve => {
    const getEventOverviewData = async () => {
      let startTime = formState.rangedate[0].format("YYYY-MM-DD");
      let endTime = formState.rangedate[1].format("YYYY-MM-DD");
      let data = {
        startTime,
        endTime,
        platformAppCodeStr: formState.applet,
        actIdStr: formState.activities,
        //参与人数 hdyx_participate_uv
        //入会人数 hdyx_join_uv
        //关注店铺人数 hdyx_subscribe_uv
        //加购商品人数 hdyx_addcart_uv
        //收藏商品人数 hdyx_favorite_uv
        //分享邀请人数 hdyx_share_uv
        eventCodeStr:
          "hdyx_participate_uv,hdyx_join_uv,hdyx_subscribe_uv,hdyx_addcart_uv,hdyx_favorite_uv,hdyx_share_uv"
      };
      let res = await eventOverview(data);
      if (res?.code === 0) {
        console.log("事件概览", res);
        if (res?.data?.date_time?.length > 0) {
          eventStatus = true;
        } else {
          eventStatus = false;
        }
        //eventOptions
        eventOptions.xAxis[0].data = res?.data?.date_time;
        for (let key in res.data.target) {
          if (key === "hdyx_participate_uv") {
            eventOptions.series[0].data = res.data.target[key].act_data;
          }
          if (key === "hdyx_join_uv") {
            eventOptions.series[1].data = res.data.target[key].act_data;
          }
          if (key === "hdyx_subscribe_uv") {
            eventOptions.series[2].data = res.data.target[key].act_data;
          }
          if (key === "hdyx_addcart_uv") {
            eventOptions.series[3].data = res.data.target[key].act_data;
          }
          if (key === "hdyx_favorite_uv") {
            eventOptions.series[4].data = res.data.target[key].act_data;
          }
          if (key === "hdyx_share_uv") {
            eventOptions.series[5].data = res.data.target[key].act_data;
          }
        }
        resolve({
          eventOptions,
          eventStatus
        });
      }
    };
    getEventOverviewData();
  });
}
